首页>代码>java Swing开发简单备忘录源代码下载>/no forget/src/com/java/panel/EditPanel.java
package com.java.panel;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import com.java.util.MyDbUtil;

/**编辑信息的面板
 * @author Mr.xiao
 *
 */
public class EditPanel extends JFrame{


	public MainPanel mp=null;
	
	JLabel jl_title=new JLabel("标题");
	JTextArea jta_title=new JTextArea();
	
	JLabel jl_content=new JLabel("内容");
	JTextArea jta_content=new JTextArea();
	
	JLabel jl_time=new JLabel("日期");
	JTextArea jta_time=new JTextArea();
	
	JButton jb_sure=new JButton("确定");
	JButton jb_cancel=new JButton("取消");
	
	public int row=0;
	
	Image icon=Toolkit.getDefaultToolkit().getImage("icon.png");

	public EditPanel(MainPanel mp,int row){
		setIconImage(icon);
		this.row=row;
		this.mp=mp;
		setTitle("编辑备忘事件");
		setVisible(true);
		getContentPane().setBackground(new Color(29,177,213));
		setLayout(null);
		setBounds(400, 100, 600, 500);
		setLayout(null);
		setResizable(false);
		
		getContentPane().add(jl_title);
		jl_title.setBounds(20, 20, 40, 30);
		
		jta_content.setBackground(new Color(199,237,204));
		jta_time.setBackground(new Color(199,237,204));
		jta_title.setBackground(new Color(199,237,204));
		
		getContentPane().add(jta_title);
		jta_title.setBounds(70,20,500,70);
		jta_title.setFont(new Font("Dialog",1,15));
		jta_title.setLineWrap(true);
		
		
		getContentPane().add(jl_content);
		jl_content.setBounds(20, 100, 40, 30);
		
		getContentPane().add(jta_content);
		jta_content.setBounds(70,100,500,200);
		jta_content.setFont(new Font("Dialog",1,15));
		jta_content.setLineWrap(true);
		
	
		getContentPane().add(jl_time);
		jl_time.setBounds(20, 310, 40, 30);
		
		getContentPane().add(jta_time);
		jta_time.setBounds(70,310,500,50);
		jta_time.setFont(new Font("Dialog",1,15));
		jta_time.setLineWrap(true);
		
		getContentPane().add(jb_sure);
		jb_sure.setBounds(100, 400, 100, 40);
		getContentPane().add(jb_cancel);
		jb_cancel.setBounds(370, 400, 100, 40);
		
		
		String title=(String)mp.jtable.getValueAt(row, 2);
		String content=(String)mp.jtable.getValueAt(row, 3);
		String time=(String)mp.jtable.getValueAt(row, 4);
		jta_title.setText(title);
		jta_content.setText(content);
		jta_time.setText(time);
		jb_cancel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		
		jb_sure.addActionListener(new EditListener(mp, this));
	}
	
	
}

class EditListener implements ActionListener{

	MainPanel mp=null;
	EditPanel ep=null;
	public EditListener(MainPanel mp,EditPanel ep) {
	this.mp=mp;
	this.ep=ep;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		String title=ep.jta_title.getText();
		String content=ep.jta_content.getText();
		String time=ep.jta_time.getText();
		if(title.length()<1||content.length()<1||time.length()<1){
			JOptionPane.showMessageDialog(null, "请将信息填写完整");
		}
		else{

			String snum = mp.jtable.getValueAt(ep.row, 1).toString();
			int num = Integer.parseInt(snum.replace("NF", ""));
			
		new MyDbUtil().addThing(num,title, content, time);
		ep.dispose();
		mp.things.removeAllElements();
		mp.things.addAll(new MyDbUtil().getAllThings()); 
		mp.jtable.updateUI();
		//JOptionPane.showMessageDialog(null, "修改成功");
		}
		
	}
	
}
最近下载更多
李朝磊  LV18 2023年11月18日
weilaizhisheng  LV21 2023年9月28日
ezra77934  LV2 2023年9月15日
alexcheung  LV3 2023年7月10日
微信网友_6292282163859456  LV4 2023年1月5日
计算机暴龙战士  LV19 2022年12月6日
a318888331  LV13 2022年10月31日
alonely23  LV1 2022年10月6日
zhendong  LV7 2022年9月26日
xiao小果  LV12 2022年6月22日
最近浏览更多
3334004690  LV3 3月6日
shiaomon 2023年12月14日
暂无贡献等级
Anzhui  LV2 2023年12月10日
李朝磊  LV18 2023年11月18日
tianshi  LV7 2023年10月19日
weilaizhisheng  LV21 2023年9月28日
ezra77934  LV2 2023年9月15日
alexcheung  LV3 2023年7月10日
ds9009  LV7 2023年6月26日
1145304128  LV12 2023年5月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友